<template>
  <div class="maincss">

    <div class="">
      <el-row>
        <el-card class="">
<!--          <searchBox title='维修记录' :btn='btn' @func='showBtn'/>-->
          <el-row class="searchbox">
            <el-col span="1"> 维修记录</el-col>
            <el-col span="3">
              <el-input
                placeholder="维修单号"
                v-model="queryParams.taskNo"
              >
              </el-input>
            </el-col>
            <el-col span="3">
              <el-input
                placeholder="仪器编号"
                v-model="queryParams.instrumentNo"
              >
              </el-input>
            </el-col>
            <!--            <el-col span="6">-->
            <!--              <el-tree-->
            <!--                :data="deptOptions"-->
            <!--                :props="defaultProps"-->
            <!--                :expand-on-click-node="false"-->
            <!--                :filter-node-method="filterNode"-->
            <!--                ref="tree"-->
            <!--                :default-expand-all="false"-->
            <!--                @node-click="handleNodeClick"-->
            <!--              />-->
            <!--            </el-col>-->
            <el-col span="6">
              <el-date-picker
                v-model="queryParams.repairTime"
                type="datetime"
                placeholder="选择日期时间"
              >
              </el-date-picker>
            </el-col>
            <el-col span="1">
              <el-button @click="handleLoadAndQuery" type="primary">查询</el-button>
            </el-col>
            <el-col span="2">
              <el-button @click="handleOpenAdd" type="primary">新增</el-button>
            </el-col>
          </el-row>
          <el-card class="gray-card no-border no-margin-top" shadow="never">
            <el-table
              v-loading="loading"
              :data="checkList"
              style="width: 100%;"
            >
              <el-table-column label="维修单号" align="center" prop="taskNo" :show-overflow-tooltip="true"/>
              <el-table-column label="仪器编号" align="center" prop="instrumentNo" :show-overflow-tooltip="true"/>
              <el-table-column label="仪器名称" align="center" prop="instrumentName"/>
              <el-table-column label="维修原因" align="center" prop="reason" :show-overflow-tooltip="true"/>
              <el-table-column label="维修人" align="center" prop="maintainer" :show-overflow-tooltip="true"/>
              <el-table-column label="联系电话" align="center" prop="contact"/>
              <el-table-column label="维修时间" align="center" prop="repairTime"/>
<!--              <el-table-column label="所属科室" align="center" prop="isReport"/>-->
              <el-table-column label="所属厂商" align="center" prop="manufacturer"/>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleEdit(scope.row, 0)"
                  >编辑
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleEdit(scope.row, 1)"
                  >详情
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>

          <pagination v-show="total>0" :total="total"
                      :page.sync="queryParams.pageNum"
                      :limit.sync="queryParams.pageSize"
                      @pagination="handleLoadAndQuery"/>


        </el-card>
      </el-row>
      <el-drawer
        title="新增维修记录"
        :visible.sync="addShow"
        size='65%'
      >
        <addcheck @closeMain='handleClose'
                  :deviceInfo="deviceInfo"
                  :editSaleInfo="editSaleInfo"
                  :flag="false"
                  :detail="detail"
                  ref="mainRef"/>
      </el-drawer>

    </div>
  </div>
</template>

<script>
import addcheck from '../deviceInfo/addMaintenance2.vue'
import {listRepairTask, getRepairTask, updateRepairTask} from "@/api/business/repairTask"
import {parseTime} from '@/utils/ruoyi'

export default {
  name: "maintenanceInfo",
  components: {
    addcheck
  },
  data() {
    return {
      btn: {
        add: true,
        reg: false,
        down: false,
        export: false,
        imp: false,
        search: true
      },
      total: 10,
      addShow: false,
      checkList: [],
      loading: false,
      redirect: undefined,
      activeName: '1',
      deviceInfo: {},
      editSaleInfo: {},
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        instrumentNo: '',
        taskNo: '',
        repairTime: ''
      },
      detail: false
    };
  },
  watch: {},
  created() {
    this.handleLoadAndQuery()
  },
  methods: {
    showBtn(data) {
      if (data == 'add') {
        this.handleOpenAdd()
      }
      if (data == 'search') {
        this.handleLoadAndQuery()
      }
    },
    handleOpenAdd() {
      this.addShow = true
    },
    handleLoadAndQuery() {
      if (this.queryParams.repairTime) {
        this.queryParams.repairTime = parseTime(this.queryParams.repairTime)
      } else {
        this.queryParams.repairTime = ''
      }
      this.loading = true;
      listRepairTask(this.queryParams).then((res) => {
        this.loading = false;
        this.total = res.total;
        this.checkList = res.rows;
      })
    },
    handleClose() {
      this.addShow = false
      this.handleLoadAndQuery()
    },
    handleEdit(row, type) {
      if (type == 1) {
        this.detail = true
      } else {
        this.detail = false
      }
      this.addShow = true
      this.$nextTick(() => {
        this.$refs.mainRef.handleData(row)
      })
    }
  }
};
</script>
